package uto.phone.flash.wind.base
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView

/**
 * 数据列表
 */
abstract class IAdapter (var dataList: MutableList<out Any> = mutableListOf(),var activity: IActivity? = null,var any: Any? = null) : RecyclerView.Adapter<IHolder>(){

    /**
     * 创建Holder
     */
    final override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): IHolder {
        return createHolder(parent,viewType)
    }

    /**
     * 创建Holder
     */
    abstract fun createHolder(parent: ViewGroup, viewType: Int): IHolder

    /**
     * 删除Item
     */
    open fun remove(holder: IHolder){
        if(holder.adapterPosition < dataList.size){
            dataList.removeAt(holder.adapterPosition)
            notifyItemRemoved(holder.adapterPosition)
        }
    }

    /**
     * 绑定Holder
     */
    final override fun onBindViewHolder(holder: IHolder, position: Int, payloads: MutableList<Any>) {
        super.onBindViewHolder(holder, position, payloads)
    }

    /**
     * 绑定Holder
     */
    final override fun onBindViewHolder(holder: IHolder, position: Int) {
        bindHolder(holder,position)
    }

    /**
     * 绑定Holder
     */
    open fun bindHolder(holder: IHolder, position: Int){
        holder.bindData(dataList.getOrNull(position))
    }

    /**
     * 获取Item数量
     */
    override fun getItemCount(): Int {
        return dataList.size
    }



}
